<template>
  <div class="all">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户列表</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="huan" style="width: 1124px;height: 297px; display: flex;flex-direction: column;">
      <div>
        <el-input placeholder="请输入内容" style="width:40vw;" v-model="input"></el-input>
        <el-button icon="el-icon-search"></el-button>
        <el-button style="margin-left: 10px;" type="primary">添加用户</el-button>
      </div>
      <el-table :data="user" border style="width: 100%;margin-top: 20px;">
        <el-table-column label="姓名" prop="username" width="180"></el-table-column>
        <el-table-column label="邮箱" prop="email" width="180"></el-table-column>
        <el-table-column label="电话" prop="mobile" width="180"></el-table-column>
        <el-table-column label="角色" prop="role_name" width="180"></el-table-column>
        <el-table-column label="状态" prop="mg_state" width="180">
          <el-tooltip>
            <el-switch
              active-color="#13ce66"
              inactive-color="#ff4949"
              inactive-value="0"
              v-model="boolean"
            ></el-switch>
          </el-tooltip>
        </el-table-column>
        <el-table-column label="操作" prop="address">
          <template #default="{ row }">
          <el-button icon="el-icon-edit" type="primary"></el-button>
          <el-button icon="el-icon-delete" type="danger" @click="del(row.id)"></el-button>
          <el-button icon="el-icon-star-off" type="warning"></el-button>
        </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          :current-page="currentPage4"
          :page-size="100"
          :page-sizes="[100, 200, 300, 400]"
          :total="400"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
          layout="total, sizes, prev, pager, next, jumper"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import { getUesr , delUser } from '@/api/user.js'
export default {
  name: 'Userlist',
  data () {
    return {
      input: '',
      user: [],
      query: '',
      pagenum: 1,
      pagesize: 2,
      boolean: false,
      currentPage1: 5,
      currentPage2: 5,
      currentPage3: 5,
      currentPage4: 4
    }
  },
  created () {
    this.getUse()
  },
  computed: {
  },
  methods: {
    async getUse () {
      const res = await getUesr(this.query, this.pagenum, this.pagesize)
      console.log(res);
      this.user = res.data.users
    },
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange (val) {
      console.log(`当前页: ${val}`);
    },
    async del (id) {
  await delUser(id)
  this.getUse()
  this.$message.success('删除成功')
  }
}
  }

</script>
<style lang='less'  scoped>
.all {
  width: 100%;
  padding: 15px;
  .huan {
    padding: 20px;
  }
}
</style>
